package sy.util;


import java.io.IOException;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * 巡更平台辅助类
 * @author xieyuanqiu
 *
 */
public class XGInterface {
	private static final String server = "https://192.168.200.111:8443/zhwy/rest/v1";
	//token有效期8小时，过期后可调用getRequestToken()获取新的token
	public static String getRequestToken(){
		String str = "";
		try {
			String result = HttpUtils.sendGetRest(server+"/admin/system/request_token", "GET");
			JSONObject obj = JSONObject.parseObject(result);
			str = obj.getString("token");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return str;
	}
	public static void main(String[] args){
		String reportUrl = "https://192.168.200.111:8443/zhwy/rest/v1/elecs";
/*		String reportUri = reportUrl + "?token=4f69a9b3da9f4afdab4ff8e20484c151&startTime="+URLEncoder.encode(DateUtil.getCurrentDateTimeString())+
				"&endTime="+URLEncoder.encode(DateUtil.getCurrentDateTimeString());*/
		String reportUri = reportUrl + "?token=7812f84ee3ec474a95e29e17f7185bf3&areaId=3";
		System.out.println(reportUri);
		String reportResult;
		try {
			//reportResult = HttpUtils.sendGetRest(reportUri, "GET");
			//JSONArray reportArr = JSONArray.parseArray(reportResult);
			//System.out.println(reportResult);
		}catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.println(getRequestToken());
	}
}
